All files / src/app/(site)/support/tickets/[id] page.tsx

0% Statements 0/51
100% Branches 0/0
0% Functions 0/1
0% Lines 0/51

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                                                                                       
export const dynamic = "force-dynamic";

import { Metadata } from 'next';
import { redirect, notFound } from 'next/navigation';
import { auth } from '@/lib/auth/auth';
import { prisma } from '@/lib/prisma';
import TicketDetailWrapper from './TicketDetailWrapper';

interface PageProps {
  params: Promise<{ id: string }>;
}

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
  const { id } = await params;
  const ticket = await prisma.supportTicket.findUnique({
    where: { id },
    select: { ticketNumber: true, subject: true }});

  if (!ticket) {
    return { title: 'Ticket Not Found | Elite Events' };
  }

  return {
    title: `${ticket.ticketNumber}: ${ticket.subject} | Elite Events`,
    description: `View support ticket ${ticket.ticketNumber}`};
}

export default async function TicketDetailPage({ params }: PageProps) {
  const session = await auth();

  if (!session?.user) {
    const { id } = await params;
    redirect(`/signin?callbackUrl=/support/tickets/${id}`);
  }

  const { id } = await params;
  const userId = (session.user as { id: number }).id;

  // Verify ticket belongs to user
  const ticket = await prisma.supportTicket.findFirst({
    where: {
      id,
      userId: userId},
    select: { id: true }});

  if (!ticket) {
    notFound();
  }

  return <TicketDetailWrapper ticketId={id} />;
}